package cfg

import (
	"gopkg.in/yaml.v3"
	"io/ioutil"
	"log"
)

type ServerListen struct {
	Ip   string `yaml:"ip"`
	Port string `yaml:"port"`
}

type DialTimeOut struct {
	Timeout int `yaml:"timeout"`
}

type YamlCfg struct {
	ServerListen ServerListen `yaml:"ServerListen"`
	DialTimeOut  DialTimeOut  `yaml:"DialTimeOut"`
}

func ReadYamlCfg(filePath string) *YamlCfg {
	var config YamlCfg
	content, err := ioutil.ReadFile(filePath)
	if err != nil {
		log.Fatalf("read config file Err: %v", err)
	}
	if err = yaml.Unmarshal([]byte(content), &config); err != nil {
		log.Fatalf("unmarshal config file Err: %v", err)
	}
	return &config
}
